#pragma once

#include "Communal.h"

template<size_t BITS>
class PageMap
{
public:
	PageMap()
	{
		size_t size = sizeof(void*) * _length;
		size_t alignSize = SizeClass::AlignUp(size);
		_array = (void**)SystemAlloc(alignSize >> PAGE_SHIFT);
		memset(_array, 0, alignSize);
	}

	void set(PAGE_ID id, void* ptr)
	{
		_array[id] = ptr;
	}

	void* get(PAGE_ID id)
	{
		if ((id >> BITS) > 0) return nullptr;
		return _array[id];
	}

private:
	size_t _length = 1 << BITS;
	void** _array = nullptr;
};